import fetch from '@/utils/request';

const API_CATEGORY_URL = '/api/user/category';
/**
 * 分类API对象
 * @module CategoryApi
 */
const CategoryApi = {
	/**
	 * @function query
	 * @description 查询分类
	 * @param  {number} type 分类类型
	 * @param  {number} level 分类层级
	 * @param  {string} parentId 父id
	 */
	query: (type, level, parentId) => fetch.request({
		url: `${API_CATEGORY_URL}/query`,
		method: 'POST',
		data: {
			type: type,
			level: level,
			parentId: parentId
		},
	}),
	/**
	 * @function queryOne
	 * @description 查询一级分类
	 * @param  {number} type 分类类型
	 */
	queryOne: (type) => fetch.request({
		url: `${API_CATEGORY_URL}/query`,
		method: 'POST',
		data: {
			type: type,
			level: 1
		},
	}),
	/**
	 * @function queryTwo
	 * @description 查询二级分类
	 * @param  {number} type 分类类型
	 * @param  {string} parentId 父id
	 */
	queryTwo: (type, parentId) => fetch.request({
		url: `${API_CATEGORY_URL}/query`,
		method: 'POST',
		data: {
			type: type,
			level: 2,
			parentId: parentId
		},
	}),
	/**
	 * @function queryThree
	 * @description 查询三级分类
	 * @param  {number} type 分类类型
	 * @param  {string} parentId 父id
	 */
	queryThree: (type, parentId) => fetch.request({
		url: `${API_CATEGORY_URL}/query`,
		method: 'POST',
		data: {
			type: type,
			level: 3,
			parentId: parentId
		},
	}),
};
export default CategoryApi;